<?php

namespace App\Models;

use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;

class Navigation extends Model
{
    use ModelTree;
    use AdminBuilder;

    protected $table = 'navigation';

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->setParentColumn('parent_id');
    }

    protected function setUrlAttribute($value){
        if (strpos($value, 'http') !== false) {
            $this->attributes['url'] = $value;
        }else{
            $this->attributes['url'] = route($value);
        }
    }
}
